home *** CD-ROM | disk | FTP | other *** search
/ stazsoftware.com / www.stazsoftware.com.tar / www.stazsoftware.com / futurebasic / sample-code / AppleScriptFB.sit / USR AppleScriptRun next >
Text File  |  2004-02-10  |  5KB  |  209 lines

  1. /*
  2.      This example tests a few AppleScript scripts.
  3.  
  4.                                                Alain   ( 9/5/02 }
  5. */
  6. '~'6
  7.  
  8. #if def _usingLiteRuntime
  9. Print "This example is not designed to work in the Console"
  10. #else
  11.  
  12. include "Subs AppleScript.Incl"
  13.  
  14. local fn doAppleScript( whichOne as int )
  15. '~'9
  16. dim as str255 message
  17. dim as handle resultH
  18. dim as OSErr  err
  19.  
  20. route _toAppleScript
  21.  
  22. select whichOne
  23.  
  24. case 1
  25. print "tell application ""Finder"""
  26. print "  the name of the startup disk"
  27. print "end tell"
  28.  
  29. case 2
  30. print "tell application ""Finder"""
  31. print "  the name of every disk"
  32. print "end tell"
  33.  
  34. case 3
  35. print "tell application ""Finder"""
  36. print "  set nbFolders to the count of folders of the startup disk"
  37. print "  say ""[[emph +]]I [[emph +]]can't believe it!"""
  38. print "  say ""You have "" & nbFolders & "" folders on your hard drive"""
  39. print "end tell"
  40.  
  41. case 4
  42. print "tell application ""Finder"""
  43. print "  the name of every folder of the startup disk"
  44. print "end tell"
  45.  
  46. case 5
  47. print "tell application ""Finder"""
  48. print "  the last folder of the startup disk"
  49. print "end tell"
  50.  
  51. case 6
  52. print "tell application ""Finder"""
  53. print "  the name of every folder of the startup disk whose label index is not 0"
  54. print "end tell"
  55.  
  56. case 7
  57. print "tell application ""Finder"" to count every file of startup disk"
  58.  
  59. case 8
  60. print "tell application ""Finder"""
  61. print "  if folder ""Apple Extras"" of startup disk exists then"
  62. print "    count files in folder ""Apple Extras"" of startup disk"
  63. print "  else"
  64. print "    return ""no Apple Extras folder found"""
  65. print "  end if"
  66. print "end tell"
  67.  
  68. case 9
  69. print "return path to me as string"
  70.  
  71. case 11
  72. print "tell application ""Finder"""
  73. print "  activate"
  74. print "  display dialog ""What's your name?"""
  75. print "end tell"
  76.  
  77. case 12
  78. print "set theCount to number of files in front window of application ""Finder"""
  79. print "if theCount > 50 then"
  80. print "  display dialog ""You have exceeded your file limit."""
  81. print "else"
  82. print "  display dialog ""You're a good boy!"""
  83. print "end if"
  84.  
  85. case 13
  86. print "display dialog ""Ready to test your patience?"""
  87. print "set myDate to current date"
  88. long if system(_sysVers) > 810
  89. print "delay 4"
  90. xelse
  91. print "╟event sysodela╚ 4"
  92. end if
  93. print "display dialog ""4 second delay on "" & (date string of myDate) & ""."""
  94.  
  95. case 15
  96. print "set myself to path to me as alias"
  97. print "tell application ""Finder"""
  98. print "  try
  99. print "    make new alias file at apple menu items folder to myself"
  100. print "  on error"
  101. print "    error ""Une erreur est survenue lors de la crÄation de l╒alias."""
  102. print "  end try"
  103. print "end tell"
  104.  
  105. case 16
  106. print "tell application ""Finder""" 
  107. print "  set appPath to """""
  108. print "  try"
  109. print "    set appPath to application file id ""RSED"" as string"
  110. print "  end try"
  111. print "end tell"
  112.  
  113. print "if appPath ¡ """" then"
  114. print "  with timeout of 5 seconds"
  115. print "    launch application appPath"
  116. print "  end timeout"
  117. print "else"
  118. print "  return ""not found"""
  119. print "end if"
  120.  
  121. case 17
  122. print "tell application ""AppleWorks"""
  123. print "  make new document at beginning with properties {name:""New Report""}"
  124. print "end tell"
  125.  
  126. case 18
  127. print "on factorial(x)"
  128. print "  if x > 0 then"
  129. print "    return x * (factorial(x - 1))"
  130. print "  else"
  131. print "    return 1"
  132. print "  end if"
  133. print "end factorial"
  134.  
  135. print "return factorial(10)"
  136.  
  137. case 20
  138. print "the current date as string"
  139.  
  140. end select
  141.  
  142. route _toScreen
  143.  
  144. err = usr AppleScriptRun( message )
  145. // result must be extracted even when an error has occurred.
  146. resultH = usr AppleScriptGetResult
  147. long if resultH
  148. call TESetText([resultH],fn GetHandleSize( resultH ), tehandle( 1 ))
  149. call DisposeHandle( resultH )
  150. cls
  151. print "Choose a script under the Script menu"
  152. xelse
  153. edit$( 1 ) = message
  154. end if
  155.  
  156. end fn
  157.  
  158. local fn doMenu
  159. '~'9
  160. dim as short menuID, itemID
  161.  
  162. menuID = menu( _menuID )
  163. itemID = menu( _itemID )
  164.  
  165. select menuID
  166. case 1 : end
  167. case 3 : fn doAppleScript( itemID )
  168. end select
  169. menu
  170. end fn
  171.  
  172. '~Main program
  173.  
  174. menu 1,0,_enable,"File"
  175. menu 1,1,_enable,"Quit/Q"
  176. edit menu 2
  177. menu 3,0,_enable,"Script"
  178. menu 3,1,_enable,"Name of Startup Disk"
  179. menu 3,2,_enable,"List of Mounted Disks"
  180. menu 3,3,_enable,"Number of Folders at Root Level"
  181. menu 3,4,_enable,"List of Folders at Root Level"
  182. menu 3,5,_enable,"Last Folder of Root Level"
  183. menu 3,6,_enable,"Labelled Folders at Root Level"
  184. menu 3,7,_enable,"Number of Files at Root Level"
  185. menu 3,8,_enable,"Number of Files in Extras Folder"
  186. menu 3,9,_enable,"My file access path"
  187. menu 3,11,_enable,"Display Dialog"
  188. menu 3,12,_enable,"Conditional Dialog"
  189. menu 3,13,_enable,"Delay"
  190. menu 3,15,_enable,"Create an Alias in Apple Menu"
  191. menu 3,16,_enable,"Launch ResEdit"
  192. menu 3,17,_enable,"New AppleWorks Document"
  193. menu 3,18,_enable,"Recursive Function Called"
  194. menu 3,20,_enable,"Current date"
  195.  
  196. window 1
  197.  
  198. print "Choose a script under the Script menu"
  199. _fldMargin = 32
  200. edit field 1,"",(_fldMargin,_fldMargin)-(Window(_width)-_fldMargin,Window(_height)-_fldMargin)
  201.  
  202. on menu fn doMenu
  203.  
  204. do
  205. handleevents
  206. until _nil
  207.  
  208. #endif
  209.